home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / gear.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  126 lines

  1. ; $Id: gear.pro,v 1.3 1997/01/15 04:21:02 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO GEAR,FRONT, REAR        ; Help pick bike gears
  7. ;+NODOCUMENT
  8. ; NAME:
  9. ;    GEAR
  10. ;
  11. ; PURPOSE:
  12. ;    Graphically display how the front and rear gears of a bike
  13. ;    interact by calculating the "inches of chain" for each
  14. ;    combination.  Inches of chain (as used here) is calculated as:
  15. ;
  16. ;        IOC = (# chainring teeth)/(# freewheel teeth) * 27
  17. ;
  18. ;    The 27 is for a 27" wheel, but 27 is generally used for all
  19. ;    wheels.  Inches of chain is a relative measure, so the difference
  20. ;    is not important.  Also 700C wheels are pretty close to 27" anyway.
  21. ;
  22. ; CATEGORY:
  23. ;    ?? - Misc.
  24. ;
  25. ; CALLING SEQUENCE:
  26. ;    GEAR, Front, Rear
  27. ;
  28. ; INPUTS:
  29. ;    Front:    A scalar, or vector.  Each element contains the number
  30. ;        of teeth on one of the chainrings, in increasing
  31. ;        order (e.g. [36, 42, 52]).
  32. ;
  33. ;    Rear:    A vector.  Each element contains the number
  34. ;        of teeth on one of the freewheel cluster, in increasing
  35. ;        order (e.g. [13, 15, 17, 19, 21, 24]).
  36. ;        of the front chainring.
  37. ;
  38. ; OUTPUTS:
  39. ;    None.
  40. ;
  41. ; COMMON BLOCKS:
  42. ;    None.
  43. ;
  44. ; SIDE EFFECTS:
  45. ;    GEAR produces two side-by-side plots.  The first shows the inches of 
  46. ;    chain as a function of the freewheel gear while holding the chainring 
  47. ;    size constant.  The second shows how the front and rear gears must
  48. ;    be switched to move through the possible settings in a monotonic way. 
  49. ;    This plot allows you to see duplications in gear combinations.
  50. ;
  51. ; RESTRICTIONS:
  52. ;    This routine can't handle a single gear setup, but it would be 
  53. ;    meaningless anyway.
  54. ;
  55. ; MODIFICATION HISTORY:
  56. ;    23, June, 1988, Written by AB, RSI.
  57. ;-
  58. ;
  59. ;
  60.   on_error, 2        ; Return to caller if an error occurs
  61.  
  62.   f_size = size(front)
  63.   IF (f_size[0] EQ 0) THEN BEGIN
  64.     f_front = FLTARR(1)
  65.     f_front[0] = FLOAT(front)
  66.     f_size = size(f_front)
  67.   ENDIF ELSE f_front = FLOAT(front)
  68.  
  69.   r_size = size(rear)
  70.   f_rear = FLOAT(rear)
  71.  
  72.   if ((f_size[0] ne 1) or (r_size[0] ne 1)) then begin
  73.     message, 'FRONT and/or REAR have the wrong number of dimensions.'
  74.     endif
  75.  
  76.   chainrings = f_size[1]
  77.   cogs = r_size[1]
  78.  
  79.   ratio = {gear_struct, front:0.0, rear:0.0, inches:0.0}
  80.   ratio = replicate(ratio,chainrings, cogs)
  81.   for I = 0, chainrings-1 do ratio[I,*].front = f_front[I]
  82.   for I = 0, cogs-1 do ratio[*,I].rear = f_rear[I]
  83.   ratio.inches = 27. * ratio.front / ratio.rear
  84.  
  85.  
  86.   OLD_P_MULTI = !P.MULTI                ; Remember
  87.   !P.MULTI = [0, 2, 0, 0, 0]
  88.  
  89.   OLD_FONT = !P.FONT
  90.   if (!D.NAME eq "PS") then !P.FONT = 0 else !P.FONT = -1
  91.  
  92.   ; Basic Plot
  93.   PLOT, F_REAR, F_FRONT , $
  94.     XRANGE=[min(F_REAR), max(F_REAR)], $
  95.     YRANGE=[min(RATIO.INCHES), max(RATIO.INCHES)], $
  96.     XTITLE = 'Teeth (Rear Cluster)', $
  97.     YTITLE = 'Inches of Chain', $
  98.     TITLE = 'Gearing By Chainring', FONT = 0, /NODATA, $
  99.     XSTYLE=2, YSTYLE=2, XTICKS = cogs-1, XTICKV=f_rear
  100.   for I = 0, CHAINRINGS-1 do begin
  101.     yval = ratio[I,*].inches
  102.     OPLOT, f_rear, yval, PSYM=(-4-i)
  103.     tmp = STRING('Crank = ', f_front[i], FORMAT='(a, I0)')
  104.     XYOUTS,f_rear[0]+.2, yval[0], TMP,size=.5
  105.     endfor
  106.  
  107.   ; Shifting pattern plot
  108.   ind = SORT(ratio.inches)
  109.   PLOT, ratio[ind].front, ratio[ind].inches , $
  110.     XRANGE=[min(F_FRONT)-5, max(F_FRONT)+5], $
  111.     YRANGE=[min(RATIO.INCHES), max(RATIO.INCHES)], $
  112.     XTITLE = 'Teeth (Front Chainring)', $
  113.     YTITLE = 'Inches of Chain', $
  114.     TITLE = 'Monotonic Curve', FONT = 0, XSTYLE=2, YSTYLE=2, $
  115.     XTICKS = chainrings-1, XTICKV=f_front
  116.  
  117.   for I = 0, CHAINRINGS-1 do $
  118.     for J = 0, COGS-1 do BEGIN
  119.       tmp = STRING(COGS-J, FORMAT='(I1)')
  120.       XYOUTS,ratio[I,J].front,ratio[I,J].inches,tmp
  121.     endfor
  122.  
  123.   !P.MULTI = OLD_P_MULTI            ; Restore
  124.   !P.FONT = OLD_FONT
  125. end
  126.